package com.yang.gateway.handler;

import com.yang.gateway.util.WebFluxUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

@Slf4j
@Configuration
public class GatewayExceptionHandler {
 
    @Bean
    @Order(-1)
    public ErrorWebExceptionHandler errorWebExceptionHandler() {
        return (exchange, ex) -> {
            // 这里可以添加日志记录、异常处理逻辑等
            log.error("网关异常拦截:{}",ex.getMessage());
            return WebFluxUtils.writeErrorResponse(exchange.getResponse(), ex.getMessage());
        };
    }
}